from exts import db
from datetime import datetime

class BannerModels(db.Model):
    __tablename__ = "banner"
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    name = db.Column(db.String(255),nullable=False)
    image_url = db.Column(db.String(255),nullable=False)
    link_url = db.Column(db.String(255),nullable=False)
    priority = db.Column(db.Integer,default=0)
    create_time = db.Column(db.DateTime,default=datetime.now)

class BoardModels(db.Model):
    __tablename__ = "board"
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    name = db.Column(db.String(50),nullable=False)
    create_time = db.Column(db.DateTime,default=datetime.now)

class PostModels(db.Model):
    __tablename__ = "post"
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    title = db.Column(db.String(50),nullable=False)
    context = db.Column(db.Text,nullable=False)
    create_time = db.Column(db.DateTime,default=datetime.now)
    #文章所属板块
    board_id = db.Column(db.Integer,db.ForeignKey("board.id"))
    author_id = db.Column(db.String(100),db.ForeignKey("front_users.id"))

    board = db.relationship("BoardModels",backref=db.backref("posts"))
    author = db.relationship("FrontUser",backref=db.backref("posts"))

class CommentsModels(db.Model):
    __tablename__ = "comment"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    context = db.Column(db.Text,nullable=False)
    create_time = db.Column(db.DateTime,default=datetime.now)
    author_id = db.Column(db.String(100),db.ForeignKey("front_users.id"))
    post_id = db.Column(db.Integer,db.ForeignKey("post.id"))

    author = db.relationship("FrontUser",backref=db.backref("comments"))
    post = db.relationship("PostModels",backref=db.backref("comments"))

class HighlightPostModels(db.Model):
    __tablename__ = "highlight"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    post_id = db.Column(db.Integer,db.ForeignKey("post.id"))
    create_time = db.Column(db.DateTime,default=datetime.now)

    post = db.relationship("PostModels",backref=db.backref("highlight"))
